package com.sy.admin.controller;

import com.sy.admin.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @GetMapping(value = "/")
    public String loginPage(){
        return "login";
    }

    @PostMapping("/login")
    public String main(User User, HttpSession HttpSession){
        if(!StringUtils.isEmpty(User.getUserName()) && !StringUtils.isEmpty(User.getPassword())){
            HttpSession.setAttribute("loginUser",User);
            return "redirect:/main.html";
        }else{
            return "login";
        }
    }

    @GetMapping("/main.html")
    public String mainPage(){

        return "main";
    }

}
